package com.malou.server.ventas.cajainicial;

import java.sql.SQLException;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.malou.client.ventas.cajainicial.CajaInicial;
import com.malou.server.base.Conexion;

public class CajaIniciales {
	
	public static SqlMapClient sqlMap = null;
	public static Integer errorTipo = 0;
	
	public static Boolean hascajainicial(CajaInicial balance){
		Boolean retorno = false;		
		try {			
	        sqlMap = Conexion.getSqlMap();
			Integer count = (Integer) sqlMap.queryForObject("getIdCajaInicial", balance);
			if(count != null){
				retorno = true;
		    }
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return retorno;
	}
	
	public static boolean save(CajaInicial balance){
		boolean retorno = true;		   
	
		sqlMap = Conexion.getSqlMap();
		try {
			if(!hascajainicial(balance)){
				sqlMap.insert("insertCajaInicial", balance);
			}else{
				errorTipo = 1; // Ya existe una caja inicial
				retorno = false;
			}
		} catch (SQLException e) {
			retorno = false;			
			e.printStackTrace();
		}
		return retorno;
	}
	
	
}
